home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / dirvcl / director.pas < prev    next >
Pascal/Delphi Source File  |  1995-12-22  |  21KB  |  696 lines

  1. unit Director;
  2. {Copyright Dr A. GUERIN and PASCALISSIME
  3.     (GUERIN Alain Georges : Compuserve  100034,2305)
  4.  This is a barterfreeware: if you find it valuable, send me something you built
  5.  YOURSELF in Delphi and you think it has more or less the same value and is as
  6.  public as this piece of software is. (So if it's used in a commercial software,
  7.  sorry for you business people, but you'll have to build something public and
  8.  free. There are particular conditions for Borland International: it's totally
  9.  free for all the company and company people, as long as they belong to B.I.
  10.  And eventually, it's a complete freeware for all TeamB people as my
  11.  debt is so high, I can never reimburse it)
  12.  If you don't have anything of this kind now, feel free to wait the necessary
  13.  time. (I will not think that your are lazy or a beginner <g>, as I have no way
  14.   to know when you got it, but please as I'm 49, don't wait to much)
  15.  Distribution is free, as long as all the files are unmodified and kept
  16.  together.
  17.  As usual there no garanty, implied or not. Use under your own responsability,
  18.  but commentaries ( even critics) in English (or in French) are wellcome}
  19. interface
  20.  
  21. uses
  22.     Classes;
  23.  
  24. CONST
  25.     MaxDirectoryLength = 79;
  26.     RS_InvalidDirectoryName        = 33001;
  27.     RS_InvalidFilterName             = 33002;
  28.    RS_InvalidDirectoryRestriction     = 33003;
  29.    RS_InvalidDirectoryExclusion         = 33004;
  30.    KVersion = 'V 1.0a - 17/05/95';
  31.  
  32. type
  33.     T_DirectoryName = STRING[MaxDirectoryLength];
  34.     TDirectory = class(TComponent)
  35.    {With this component you can get filenames in a directory
  36.        You can choose which kind of files you want by including
  37.       hidden, sysfile, volumeID or Directory attributes or by
  38.       excluding archive, readonly and even normal files.
  39.       You can choose to recurse into subdirectories or not,
  40.       and if so, you can choose in which kind of subdir you
  41.       will recurse.
  42.       For example
  43.           you can get archive and/or hidden files in the current
  44.          directory and in all the archive and/or system sub dir
  45.          by excluding readonly and normal file, including hidden
  46.          files, including system directories and excluding normal
  47.          and readonly directories
  48.        In this version, this kind of directory filter is only
  49.       implemented for subdirectories.
  50.       For getting the results, you have to implement the found method
  51.       in the target program and read through SelectedFileName in it.
  52.       You can also implement a cancel mechanism where you can trigger
  53.       the DoStop method}
  54.  
  55.    private
  56.      { Private-declarations }
  57.         FExcludeNormalFiles : BOOLEAN;
  58.       FExcludeReadOnlyFiles : BOOLEAN;
  59.       FExcludeArchiveFiles : BOOLEAN;
  60.       FIncludeHiddenFiles : BOOLEAN;
  61.       FIncludeSystemFiles : BOOLEAN;
  62.       FIncludeVolumeID : BOOLEAN;
  63.       FIncludeDirectoryFiles : BOOLEAN;
  64.         FExcludeNormalDir : BOOLEAN;
  65.       FExcludeReadOnlyDir : BOOLEAN;
  66.       FExcludeArchiveDir : BOOLEAN;
  67.       FIncludeHiddenDir : BOOLEAN;
  68.       FIncludeSystemDir : BOOLEAN;
  69.         FInSubDirectories : BOOLEAN;
  70.       FOnlyDirectories : BOOLEAN;
  71.         FStopStatus : BOOLEAN;
  72.         FInitialDirectory : PString;
  73.         FDirectoryInTreatment : PString;
  74.         FSelectedFileName : PString;
  75.         FFileFilter : PSTRING;
  76.         FDirectoryFilter : PSTRING;
  77.         FOnFound : TNotifyEvent;
  78.         FOnSearchStatus : TNotifyEvent;
  79.       FVersion : PString;
  80.           SearchFilesMask : BYTE;
  81.       SearchDirMask : BYTE;
  82.         ExcludedFilesMask : BYTE;
  83.       ExcludedDirMask : BYTE;
  84.         PROCEDURE SetInitial(Value : T_DirectoryName);
  85.         FUNCTION  GetInitial : T_DirectoryName;
  86.         PROCEDURE SetExcludeNormalFiles(Value : BOOLEAN);
  87.       PROCEDURE SetExcludeReadOnlyFiles (Value : BOOLEAN);
  88.       PROCEDURE SetExcludeArchiveFiles (Value : BOOLEAN);
  89.       PROCEDURE SetIncludeHiddenFiles (Value : BOOLEAN);
  90.       PROCEDURE SetIncludeSystemFiles (Value : BOOLEAN);
  91.       PROCEDURE SetIncludeVolumeID (Value : BOOLEAN);
  92.       PROCEDURE SetIncludeDirectoryFiles (Value : BOOLEAN);
  93.         PROCEDURE SetExcludeNormalDir (Value : BOOLEAN);
  94.       PROCEDURE SetExcludeReadOnlyDir (Value : BOOLEAN);
  95.       PROCEDURE SetExcludeArchiveDir (Value : BOOLEAN);
  96.       PROCEDURE SetIncludeHiddenDir (Value : BOOLEAN);
  97.       PROCEDURE SetIncludeSystemDir (Value : BOOLEAN);
  98.         PROCEDURE SetInSubDirectories (Value : BOOLEAN);
  99.        PROCEDURE SetOnlyDirectories (Value : BOOLEAN);
  100.         PROCEDURE SetStopStatus(Value : BOOLEAN);
  101.         PROCEDURE SetFileFilter(CONST Value : STRING);
  102.         FUNCTION  GetFileFilter : String;
  103.         PROCEDURE SetDirectoryFilter(CONST Value : STRING);
  104.         FUNCTION  GetDirectoryFilter: String;
  105.         FUNCTION  GetDirectoryInTreatment : T_DirectoryName;
  106.         PROCEDURE SetDirectoryInTreatment(Value : T_DirectoryName);
  107.         FUNCTION  GetSelectedFileName : T_DirectoryName;
  108.         PROCEDURE SetSelectedFileName (Value : T_DirectoryName);
  109.       PROCEDURE SetVersion(Value : String);
  110.       FUNCTION  GetVersion : String;
  111.   protected
  112.         property  StopStatus : BOOLEAN write SetStopStatus DEFAULT True;
  113.   public
  114.         property  Stopped : BOOLEAN read FStopStatus;
  115.         property  DirectoryInTreatment : T_DirectoryName
  116.                                                                 read     GetDirectoryInTreatment
  117.                                                                 Write SetDirectoryInTreatment;
  118.         property  SelectedFileName : T_DirectoryName read GetSelectedFileName
  119.                                                                     Write SetSelectedFileName;
  120.         CONSTRUCTOR Create(AOwner : TComponent); OVERRIDE;
  121.         DESTRUCTOR Destroy;
  122.         PROCEDURE Execute;
  123.         PROCEDURE DoStop;
  124.   published
  125.      { Published-declarations }
  126.       property Version : String read GetVersion write SetVersion;
  127.         property OnFound: TNotifyEvent read FOnFound write FOnFound;
  128.         property OnSearchStatus : TNotifyEvent    read FOnSearchStatus
  129.                                                             write FOnSearchStatus;
  130.         property InitialDir : T_DirectoryName     read GetInitial write SetInitial;
  131.         property ExcludeNormalFiles : BOOLEAN read FExcludeNormalFiles
  132.                                               write SetExcludeNormalFiles;
  133.       property ExcludeReadOnlyFiles : BOOLEAN read FExcludeReadOnlyFiles
  134.                                               write SetExcludeReadOnlyFiles;
  135.       property ExcludeArchiveFiles : BOOLEAN read FExcludeArchiveFiles
  136.                                               write SetExcludeArchiveFiles;
  137.       property IncludeHiddenFiles : BOOLEAN read FIncludeHiddenFiles
  138.                                               write SetIncludeHiddenFiles;
  139.       property IncludeSystemFiles : BOOLEAN read FIncludeSystemFiles
  140.                                               write SetIncludeSystemFiles;
  141.       property IncludeVolumeID : BOOLEAN read FIncludeVolumeID
  142.                                               write SetIncludeVolumeID;
  143.       property IncludeDirectoryFiles : BOOLEAN read FIncludeDirectoryFiles
  144.                                               write SetIncludeDirectoryFiles;
  145.         property ExcludeNormalDir : BOOLEAN read FExcludeNormalDir
  146.                                               write SetExcludeNormalDir;
  147.       property ExcludeReadOnlyDir : BOOLEAN read FExcludeReadOnlyDir
  148.                                               write SetExcludeReadOnlyDir;
  149.       property ExcludeArchiveDir : BOOLEAN read FExcludeArchiveDir
  150.                                               write SetExcludeArchiveDir;
  151.       property IncludeHiddenDir : BOOLEAN read FIncludeHiddenDir
  152.                                               write SetIncludeHiddenDir;
  153.       property IncludeSystemDir : BOOLEAN read FIncludeSystemDir
  154.                                               write SetIncludeSystemDir;
  155.         property InSubDirectories : BOOLEAN read FInSubDirectories
  156.                                                             write SetInSubDirectories;
  157.       property OnlyDirectories : BOOLEAN read FOnlyDirectories
  158.                                                           write SetOnlyDirectories;
  159.         property FileFilter : STRING read GetFileFilter Write SetFileFilter;
  160.         property DirectoryFilter: STRING read GetDirectoryFilter
  161.                                                     Write SetDirectoryFilter;
  162.     end;
  163.  
  164.  
  165.     procedure Register;
  166.  
  167. implementation
  168.  
  169. uses
  170.     Messages,
  171.     Sysutils,
  172.     WinProcs,
  173.     WinTypes;
  174.  
  175. TYPE
  176.  
  177.     EDirectoryError = Class(Exception);
  178.  
  179.     FUNCTION DirectoryValide(TestedDirectory: T_DirectoryName) : BOOLEAN;
  180.  
  181.     VAR
  182.         MaxName,
  183.         MaxExtension,
  184.         Letter : BYTE;
  185.         PreviousLetter : CHAR;
  186.         InName : BOOLEAN;
  187.  
  188.     BEGIN
  189.         MaxName := 0;
  190.         MaxExtension :=0;
  191.         Letter := 1;
  192.         InName := TRUE;
  193.         Result := TRUE;
  194.         PreviousLetter:=' ';
  195.         WHILE Result AND (Letter <= Length(TestedDirectory)) DO
  196.         BEGIN
  197.             CASE TestedDirectory[Letter] OF
  198.                 '\': BEGIN
  199.                     Result := (PreviousLetter<>'\') AND (MaxName<=8)
  200.                                         AND (MaxExtension<=3);
  201.                     MaxName:=0;
  202.                     MaxExtension:=0;
  203.                 END;
  204.                 '.': BEGIN
  205.                     Result := (MaxName > 0) AND (MaxName<=8);
  206.                     MaxName:=0;
  207.                     MaxExtension:=0;
  208.                     InName:=FALSE;
  209.                 END;
  210.                 #0..' ','/','+','=','*','?','(',')','[',']',',','|','<','>':
  211.                 {Dos forbidden characters in a filename}
  212.                     Result := FALSE;
  213.                 ':': BEGIN
  214.                     Result := Letter=2;
  215.                     MaxName:=0;
  216.                 END
  217.                 ELSE
  218.                     IF InName THEN
  219.                         INC(MaxName)
  220.                     ELSE
  221.                         INC(MaxExtension);
  222.             END;
  223.             PreviousLetter := TestedDirectory[Letter];
  224.             INC(Letter);
  225.         END;
  226.         Result := Result AND (MaxName <=8) AND (MaxExtension<=3);
  227.         IF NOT Result THEN
  228.             raise EDirectoryError.CreateResFmt(RS_InvalidDirectoryName,
  229.                                                                                 [TestedDirectory]);
  230.     END;
  231.  
  232.     FUNCTION ValidFilter(CONST TestedFilter : String) : BOOLEAN;
  233.  
  234.     CONST
  235.         Jeux_Interdits : SET OF CHAR =
  236.         {French joke, it's untranslatable}
  237.             [#0..' ','[',']','\','/','|','=','+','>','<',',',';','.',':','º'];
  238.     VAR
  239.         TestFilter : STRING;
  240.         Letter : BYTE;
  241.         Extension : String;
  242.  
  243.     BEGIN
  244.         TestFilter:= Lowercase(Copy(TestedFilter,1,11));
  245.         IF POS('.', TestFilter)> 1 THEN
  246.         BEGIN
  247.         {If the filter is too long, it's false but it does no matter: we cut it}
  248.             Extension:= Copy(TestFilter, POS('.', TestFilter)+1,3);
  249.             Delete(TestFilter, POS('.', TestFilter),255);
  250.         END
  251.         ELSE
  252.             Extension := '';
  253.         TestFilter := COPY(TestFilter,1,8);
  254.         Letter := 1;
  255.         Result := True;
  256.         WHILE (Letter <= LENGTH(TestFilter)) AND Result DO
  257.         BEGIN
  258.             Result := NOT (TestFilter[Letter] in Jeux_Interdits);
  259.             INC(Letter);
  260.         END;
  261.         Letter := 1;
  262.         WHILE (Letter <= LENGTH(Extension)) AND Result DO
  263.         BEGIN
  264.             Result := NOT (Extension[1] in Jeux_Interdits);
  265.             INC(Letter);
  266.         END;
  267.         IF NOT Result THEN
  268.             Raise EDirectoryError.CreateResfmt(RS_InvalidFilterName, [TestedFilter]);
  269.     END;
  270.  
  271.     PROCEDURE ProcessMessages;
  272.  
  273.     {as there is no Tapplication available here}
  274.  
  275.     VAR
  276.         Msg: TMsg;
  277.  
  278.     BEGIN
  279.         if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then
  280.         begin
  281.             if Msg.Message <> WM_QUIT then
  282.             begin
  283.                 TranslateMessage(Msg);
  284.                 DispatchMessage(Msg);
  285.             end
  286.       end;
  287.     END;
  288.  
  289.  
  290.     CONSTRUCTOR TDirectory.Create;
  291.  
  292.     VAR
  293.         LInitial : T_DirectoryName;
  294.  
  295.     BEGIN
  296.         INHERITED Create(AOwner);
  297.         FInitialDirectory:=NullStr;
  298.         FDirectoryInTreatment :=NullStr;
  299.         FSelectedFileName :=NullStr;
  300.         FFileFilter :=NullStr;
  301.         AssignStr(FFileFilter, '*.*');
  302.         FDirectoryFilter :=NullStr;
  303.         AssignStr(FDirectoryFilter, '*.*');
  304.       FVersion := NullStr;
  305.       AssignStr(FVersion, KVersion);
  306.           SearchFilesMask := faArchive OR faReadOnly;
  307.         ExcludedFilesMask :=0;
  308.       SearchDirMask :=faDirectory;
  309.       ExcludedDirMask :=0;
  310.     END;
  311.  
  312.     DESTRUCTOR TDirectory.Destroy;
  313.  
  314.     BEGIN
  315.         DisposeStr(FInitialDirectory);
  316.         DisposeStr(FDirectoryInTreatment);
  317.         DisposeStr(FSelectedFileName);
  318.         DisposeStr(FFileFilter);
  319.         DisposeStr(FDirectoryFilter);
  320.       DisposeStr(FVersion);
  321.         INHERITED Destroy;
  322.     END;
  323.  
  324.     PROCEDURE TDirectory.Execute;
  325.  
  326.     VAR
  327.         Filter : String;
  328.  
  329.         PROCEDURE ReadDirectory(Directory_to_Read : T_DirectoryName);
  330.  
  331.         VAR
  332.             CurrentPath : T_DirectoryName;
  333.             MyDosIOError : INTEGER;
  334.             SearchInfo : TSearchRec;
  335.  
  336.             PROCEDURE SearchFiles;
  337.  
  338.             VAR
  339.                 FileSearchInfo : TSearchRec;
  340.                 MaskFileName : T_DirectoryName;
  341.  
  342.             BEGIN
  343.                 MaskFileName := CurrentPath+FFileFilter^;
  344.                 MyDosIOError := FindFirst(MaskFileName, SearchFilesMask,
  345.                                                                                 FileSearchInfo);
  346.                 IF MyDosIOError = 0 THEN
  347.             {0 if something found, else negative DOS error code}
  348.                 REPEAT
  349.                     WITH FileSearchInfo DO
  350.                         IF ((Name<>'.') AND ( Name<>'..'))
  351.                   {Don't take in account Directory itself or its parent
  352.                    directory}
  353.                   AND (Attr AND  ExcludedFilesMask = 0)
  354.                   {There is nothing in common = no exclusion}
  355.                   AND NOT (((Attr=0)OR(Attr=faDirectory)) AND ExcludeNormalFiles) THEN
  356.                   {It's not a normal file or a normal directory
  357.                                                when normal files are excluded}
  358.                         BEGIN
  359.                       IF FOnlyDirectories AND (Attr AND faDirectory=faDirectory)
  360.                      OR NOT FOnlyDirectories THEN
  361.                      BEGIN
  362.                                 SelectedFileName:=
  363.                                             CurrentPath+FileSearchInfo.Name;
  364.                         {Signal a new file name}
  365.                                 if Assigned(FOnFound) then FOnFound(Self);
  366.                       END;
  367.                         END;
  368.                ProcessMessages;
  369.                     MyDosIOError := FindNext(FileSearchInfo);
  370.                 UNTIL (MyDosIOError < 0) OR Stopped;
  371.             END;
  372.  
  373.         BEGIN
  374.             CurrentPath := Directory_To_Read;
  375.             IF CurrentPath = '' THEN
  376.                 GetDir(0, CurrentPath);
  377.             IF NOT (CurrentPath[Length(CurrentPath)] IN ['\',':']) THEN
  378.                 CurrentPath:=CurrentPath+'\';
  379.             MyDosIOError := FindFirst(CurrentPath+FDirectoryFilter^,
  380.                                                              SearchDirMask, SearchInfo);
  381.             IF MyDosIOError = 0 THEN
  382.             BEGIN
  383.                 REPEAT
  384.                     WITH SearchInfo DO
  385.                         IF ((Name<>'.') AND ( Name<>'..'))
  386.                   {Don't take in account Directory itself or its parent
  387.                    directory}
  388.                   AND (Attr AND faDirectory=faDirectory) THEN
  389.                   {Select only Directories}
  390.                         BEGIN
  391.                             DirectoryInTreatment := CurrentPath;
  392.                             IF InSubDirectories
  393.                      AND (Attr AND  ExcludedDirMask = 0)
  394.                      {recurse in sub dir if they fit with directories selection
  395.                       criteria}
  396.                      AND NOT((Attr=faDirectory) AND ExcludeNormalDir) THEN
  397.                      {but not if it's a normal dir when normal dirs are
  398.                      excluded}
  399.                                 ReadDirectory(CurrentPath+Name);
  400.                         END;
  401.                     ProcessMessages;
  402.                     MyDosIOError := FindNext(SearchInfo);
  403.                 UNTIL (MyDosIOError < 0) OR Stopped;
  404.                 IF Stopped THEN
  405.                     Exit;
  406.                 SearchFiles
  407.             END;
  408.         END;
  409.  
  410.     BEGIN
  411.         StopStatus := FALSE;
  412.         IF DirectoryFilter = '' THEN
  413.             Filter := '*.*'
  414.         ELSE
  415.             Filter := DirectoryFilter;
  416.         ReadDirectory(FInitialDirectory^);
  417.         StopStatus := TRUE;
  418.     END;
  419.  
  420.     PROCEDURE TDirectory.DoStop;
  421.  
  422.     BEGIN
  423.         StopStatus := True;
  424.     END;
  425.  
  426.  
  427.     PROCEDURE TDirectory.SetInitial(Value : T_DirectoryName);
  428.  
  429.     BEGIN
  430.         IF NOT DirectoryValide(Value) THEN
  431.           Exit;
  432.         IF FInitialDirectory^ <> Value THEN
  433.             AssignStr( FInitialDirectory,Value);
  434.     END;
  435.  
  436.     FUNCTION TDirectory.GetInitial :T_DirectoryName;
  437.  
  438.     BEGIN
  439.         Result := FInitialDirectory^;
  440.     END;
  441.  
  442.     PROCEDURE TDirectory.SetExcludeNormalFiles (Value : BOOLEAN);
  443.  
  444.     BEGIN
  445.         IF Value <> FExcludeNormalFiles THEN
  446.             FExcludeNormalFiles := Value;
  447.     END;
  448.  
  449.    PROCEDURE TDirectory.SetExcludeReadOnlyFiles (Value : BOOLEAN);
  450.  
  451.    BEGIN
  452.        IF Value <> FExcludeReadOnlyFiles THEN
  453.       BEGIN
  454.           FExcludeReadOnlyFiles := Value;
  455.          IF Value THEN
  456.              ExcludedFilesMask := ExcludedFilesMask OR faReadOnly
  457.          ELSE
  458.              ExcludedFilesMask := ExcludedFilesMask AND NOT faReadOnly
  459.       END;
  460.    END;
  461.  
  462.    PROCEDURE TDirectory.SetExcludeArchiveFiles (Value : BOOLEAN);
  463.  
  464.    BEGIN
  465.        IF Value <> FExcludeArchiveFiles THEN
  466.       BEGIN
  467.           FExcludeArchiveFiles := Value;
  468.          IF Value THEN
  469.              ExcludedFilesMask := ExcludedFilesMask OR faArchive
  470.          ELSE
  471.              ExcludedFilesMask := ExcludedFilesMask AND NOT faArchive
  472.       END;
  473.    END;
  474.  
  475.    PROCEDURE TDirectory.SetIncludeHiddenFiles (Value : BOOLEAN);
  476.  
  477.    BEGIN
  478.        IF Value <> FIncludeHiddenFiles THEN
  479.       BEGIN
  480.           FIncludeHiddenFiles := Value;
  481.          IF Value THEN
  482.              SearchFilesMask := SearchFilesMask OR faHidden
  483.          ELSE
  484.              SearchFilesMask := SearchFilesMask AND (NOT faHidden);
  485.       END;
  486.    END;
  487.  
  488.    PROCEDURE TDirectory.SetIncludeSystemFiles (Value : BOOLEAN);
  489.  
  490.    BEGIN
  491.        IF Value <> FIncludeSystemFiles THEN
  492.       BEGIN
  493.           FIncludeSystemFiles := Value;
  494.          IF Value THEN
  495.              SearchFilesMask := SearchFilesMask OR faSysfile
  496.          ELSE
  497.              SearchFilesMask := SearchFilesMask AND NOT faSysfile
  498.       END;
  499.    END;
  500.  
  501.    PROCEDURE TDirectory.SetIncludeVolumeID (Value : BOOLEAN);
  502.  
  503.    BEGIN
  504.        IF Value <> FIncludeVolumeID THEN
  505.       BEGIN
  506.           FIncludeVolumeID := Value;
  507.          IF Value THEN
  508.              SearchFilesMask := SearchFilesMask OR faVolumeID
  509.          ELSE
  510.              SearchFilesMask := SearchFilesMask AND NOT faVolumeID
  511.       END
  512.    END;
  513.  
  514.    PROCEDURE TDirectory.SetIncludeDirectoryFiles (Value : BOOLEAN);
  515.  
  516.    BEGIN
  517.        IF NOT Value AND FOnlyDirectories THEN
  518.           Raise EDirectoryError.Create('Invalide exclusion');
  519. {          Raise EDirectoryError.CreateRes(RS_InvalidDirectoryExclusion);}
  520.        IF Value <> FIncludeDirectoryFiles THEN
  521.       BEGIN
  522.           FIncludeDirectoryFiles := Value;
  523.          IF Value THEN
  524.              SearchFilesMask := SearchFilesMask OR faDirectory
  525.          ELSE
  526.              SearchFilesMask := SearchFilesMask AND NOT faDirectory
  527.       END
  528.    END;
  529.  
  530.    PROCEDURE TDirectory.SetExcludeNormalDir (Value : BOOLEAN);
  531.  
  532.    BEGIN
  533.        IF Value <> FExcludeNormalDir THEN
  534.           FExcludeNormalDir := Value;
  535.    END;
  536.  
  537.    PROCEDURE TDirectory.SetExcludeReadOnlyDir (Value : BOOLEAN);
  538.  
  539.    BEGIN
  540.        IF Value <> FExcludeReadOnlyDir THEN
  541.       BEGIN
  542.           FExcludeReadOnlyDir := Value;
  543.          IF Value THEN
  544.              ExcludedDirMask := ExcludedDirMask OR faReadOnly
  545.          ELSE
  546.              ExcludedDirMask := ExcludedDirMask AND NOT faReadOnly
  547.       END;
  548.    END;
  549.  
  550.    PROCEDURE TDirectory.SetExcludeArchiveDir (Value : BOOLEAN);
  551.  
  552.    BEGIN
  553.        IF Value <> FExcludeArchiveDir THEN
  554.       BEGIN
  555.           FExcludeArchiveDir := Value;
  556.          IF Value THEN
  557.              ExcludedDirMask := ExcludedDirMask OR faArchive
  558.          ELSE
  559.              ExcludedDirMask := ExcludedDirMask AND NOT faArchive
  560.       END;
  561.    END;
  562.  
  563.    PROCEDURE TDirectory.SetIncludeHiddenDir (Value : BOOLEAN);
  564.  
  565.    BEGIN
  566.        IF Value <> FIncludeHiddenDir THEN
  567.       BEGIN
  568.           FIncludeHiddenDir := Value;
  569.          IF Value THEN
  570.              SearchDirMask := SearchDirMask OR faHidden
  571.          ELSE
  572.              SearchDirMask := SearchDirMask AND NOT faHidden
  573.       END;
  574.    END;
  575.  
  576.    PROCEDURE TDirectory.SetIncludeSystemDir (Value : BOOLEAN);
  577.  
  578.    BEGIN
  579.        IF Value <> FIncludeSystemDir THEN
  580.       BEGIN
  581.           FIncludeSystemDir := Value;
  582.          IF Value THEN
  583.              SearchDirMask := SearchDirMask OR faSysfile
  584.          ELSE
  585.              SearchDirMask := SearchDirMask AND NOT faSysfile
  586.       END;
  587.    END;
  588.  
  589.     PROCEDURE TDirectory.SetStopStatus(Value : BOOLEAN);
  590.  
  591.     BEGIN
  592.         if FStopStatus <> Value THEN
  593.             FStopStatus := Value;
  594.         if Assigned(FOnSearchStatus) then FOnSearchStatus(Self);
  595.     END;
  596.  
  597.     PROCEDURE TDirectory.SetInSubDirectories (Value : BOOLEAN);
  598.  
  599.     BEGIN
  600.         IF FInSubDirectories <> Value THEN
  601.             FInSubDirectories:= Value;
  602.     END;
  603.  
  604.    PROCEDURE TDirectory.SetOnlyDirectories (Value : BOOLEAN);
  605.  
  606.    BEGIN
  607.        IF Value and NOT FIncludeDirectoryFiles THEN
  608. {          Raise EDirectoryError.Create('Invalid restriction');}
  609.           Raise EDirectoryError.CreateRes(RS_InvalidDirectoryRestriction);
  610.        IF FOnlyDirectories <> Value THEN
  611.           FOnlyDirectories := Value;
  612.    END;
  613.  
  614.     PROCEDURE TDirectory.SetFileFilter(CONST Value : STRING);
  615.  
  616.     VAR
  617.         FileFilter : STRING;
  618.  
  619.     BEGIN
  620.         FileFilter := Value;
  621.         IF NOT ValidFilter(FileFilter) THEN
  622.             exit;
  623.         IF (FFileFilter^ <> FileFilter) THEN
  624.             AssignStr(FFileFilter, FileFilter);
  625.     END;
  626.  
  627.     FUNCTION TDirectory.GetFileFilter : String;
  628.  
  629.     BEGIN
  630.         Result := FFileFilter^
  631.     END;
  632.  
  633.     PROCEDURE TDirectory.SetDirectoryFilter(CONST Value : STRING);
  634.  
  635.     VAR
  636.         DirectoryFilter: STRING;
  637.  
  638.     BEGIN
  639.         DirectoryFilter := Value;
  640.         IF ValidFilter(DirectoryFilter)
  641.         AND (FDirectoryFilter^ <> DirectoryFilter) THEN
  642.             AssignStr(FDirectoryFilter, DirectoryFilter);
  643.     END;
  644.  
  645.     FUNCTION TDirectory.GetDirectoryFilter : String;
  646.  
  647.     BEGIN
  648.         Result := FDirectoryFilter^
  649.     END;
  650.  
  651.     PROCEDURE TDirectory.SetDirectoryInTreatment(Value : T_DirectoryName);
  652.  
  653.     BEGIN
  654.         IF Value <> FDirectoryInTreatment^ THEN
  655.             AssignStr(FDirectoryInTreatment, Value)
  656.     END;
  657.  
  658.     FUNCTION TDirectory.GetDirectoryInTreatment : T_DirectoryName;
  659.  
  660.     BEGIN
  661.         Result := FDirectoryInTreatment^
  662.     END;
  663.  
  664.     PROCEDURE TDirectory.SetSelectedFileName(Value : T_DirectoryName);
  665.  
  666.     BEGIN
  667.         IF Value <> FSelectedFileName^ THEN
  668.             AssignStr(FSelectedFileName, Value);
  669.     END;
  670.  
  671.     FUNCTION TDirectory.GetSelectedFileName : T_DirectoryName;
  672.  
  673.     BEGIN
  674.         Result := FSelectedFileName^
  675.     END;
  676.  
  677.    FUNCTION TDirectory.GetVersion : String;
  678.  
  679.    BEGIN
  680.        Result := FVersion^;
  681.    END;
  682.  
  683.    PROCEDURE TDirectory.SetVersion(Value : String);
  684.  
  685.    BEGIN
  686.         IF Value <> FVersion^ THEN
  687.             AssignStr(FVersion, KVersion);
  688.    END;
  689.  
  690.     procedure Register;
  691.  
  692.     begin
  693.         RegisterComponents('AgVCL', [TDirectory]);
  694.     end;
  695. end.
  696.